package com.joeyzh.table;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.joeyzh.utils.ModelGetSetUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Joey on 2018/12/26.
 *
 * @author by Joey
 */

public class TableLogEntity {

    /**
     * OperationCode : Replacement
     * Text : 启炉置换
     * ParamValues : [{"Text":"(1)将还原炉充氮气至 0.30\u20140.35Mpag，确认炉前无明显泄露;","ParamCode":"ChargingNitrogen","Type":"Checked"},{"Text":"(2)将氢气压力充至 0.60Mpag，氢气检漏仪检漏;","ParamCode":"HydrogenPressure","Type":"Checked"},{"Text":"(3)抽真空至-0.099Mpag，保持压力氮气吹扫 1h;","ParamCode":"Vacuumize","Type":"Checked"},{"Text":"(4)氮气压力至 0.35Mpag。","ParamCode":"NitrogenPressure","Type":"Checked"}]
     */
    @Expose()
    @SerializedName(value = "NId", alternate = {"OperationCode", "OperationNId"})
    private String OperationCode;
    /**
     * 表单标题
     */
    private String Text;
    @Expose()
    @SerializedName(value = "WorkOrderParamList", alternate = {"ParamValues", "WorkOrderParamRecordList"})
    private List<TableLogItemEntity> ParamValues = new ArrayList<>();
    private List<TableLogItemEntity> ImageValues = new ArrayList<>();
    private List<TableLogItemEntity> CustomValues = new ArrayList<>();
    private List<TableLogItemEntity> MutiValues = new ArrayList<>();
    /**
     * 用于读取某项item
     */
    private HashMap<String, TableLogItemEntity> itemEntityHashMap = new HashMap<>();
    private String itemListJson;
    private boolean editable = true;

    public TableLogEntity() {
    }

    public String getOperationCode() {
        return OperationCode;
    }

    public void setOperationCode(String OperationCode) {
        this.OperationCode = OperationCode;
    }

    public String getText() {
        return Text;
    }

    public void setText(String Text) {
        this.Text = Text;
    }

    public List<TableLogItemEntity> getParamValues() {
        return ParamValues;
    }

    public void setParamValues(List<TableLogItemEntity> value) {
        this.ParamValues = value;
    }


    public List<TableLogItemEntity> getImageValues() {
        return ImageValues;
    }

    public void setImageValues(List<TableLogItemEntity> imageValues) {
        ImageValues = imageValues;
    }

    public List<TableLogItemEntity> getCustomValues() {
        return CustomValues;
    }

    public void setCustomValues(List<TableLogItemEntity> customValues) {
        CustomValues = customValues;
    }

    public List<TableLogItemEntity> getMutiValues() {
        return MutiValues;
    }

    public void setMutiValues(List<TableLogItemEntity> mutiValues) {
        this.MutiValues = mutiValues;
    }


    public HashMap<String, TableLogItemEntity> getItemEntityHashMap() {
        return itemEntityHashMap;
    }

    public void setItemEntityHashMap(HashMap<String, TableLogItemEntity> itemEntityHashMap) {
        this.itemEntityHashMap = itemEntityHashMap;
    }

    public String getItemListJson() {
        List<TableLogItemEntity> list = new ArrayList<>();
        //没有数据
        if (null == itemListJson || itemListJson.isEmpty()) {
            if (!getParamValues().isEmpty()) {
                for (TableLogItemEntity item : getParamValues()) {
                    if (null == item.getParamValue() || item.getParamValue().isEmpty()) {
                        continue;
                    }
                    list.add(item);
                }
                if (!list.isEmpty()) {
                    itemListJson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(list);
                }
            }
        }
        return itemListJson;
    }

    public void setItemListJson(String json) {
        itemListJson = json;
    }

    public boolean isEditable() {
        return editable;
    }

    public void setEditable(boolean editable) {
        this.editable = editable;
    }


    public <T> T convertToObject(T t) {
        if (getParamValues() == null) {
            return null;
        }
        ModelGetSetUtil<T> util = new ModelGetSetUtil<>(t);
        for (TableLogItemEntity item : getParamValues()) {
            util.setValue(item.getParamCode(), item.getParamValue());
        }
        return t;
    }
}
